<template>
  <view class="profile-page">
    <!-- 状态栏 -->
    <view class="status-bar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
    
    <!-- 头部 -->
    <view class="header">
      <view class="header-content">
        <text class="title">我的</text>
        <view class="header-actions">
          <view class="action-btn" @click="goToSettings">
            <text class="action-text">设置</text>
          </view>
        </view>
      </view>
    </view>

    <!-- 用户信息 -->
    <view class="user-info">
      <view class="user-avatar">
        <image :src="userInfo.avatar" mode="aspectFill" class="avatar" />
        <view class="edit-avatar" @click="changeAvatar">
          <text class="edit-icon">📷</text>
        </view>
      </view>
      <view class="user-details">
        <text class="user-name">{{ userInfo.name }}</text>
        <text class="user-phone">{{ userInfo.phone }}</text>
        <view class="user-status">
          <text class="status-text">{{ userInfo.status }}</text>
        </view>
      </view>
      <view class="edit-btn" @click="editProfile">
        <text class="edit-text">编辑</text>
      </view>
    </view>

    <!-- 数据统计 -->
    <view class="stats-section">
      <view class="stats-item" @click="goToOrders">
        <text class="stats-number">{{ userStats.totalOrders }}</text>
        <text class="stats-label">总订单</text>
      </view>
      <view class="stats-item" @click="goToFinance">
        <text class="stats-number">¥{{ userStats.totalIncome }}</text>
        <text class="stats-label">总收入</text>
      </view>
      <view class="stats-item" @click="goToReviews">
        <text class="stats-number">{{ userStats.rating }}</text>
        <text class="stats-label">评分</text>
      </view>
      <view class="stats-item" @click="goToTasks">
        <text class="stats-number">{{ userStats.completedTasks }}</text>
        <text class="stats-label">完成任务</text>
      </view>
    </view>

    <!-- 功能菜单 -->
    <view class="menu-section">
      <view class="menu-group">
        <view class="menu-item" @click="goToOrders">
          <view class="menu-icon">📋</view>
          <text class="menu-text">订单管理</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToTasks">
          <view class="menu-icon">🔧</view>
          <text class="menu-text">维修任务</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToCoupons">
          <view class="menu-icon">🎫</view>
          <text class="menu-text">卡券管理</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToActivities">
          <view class="menu-icon">🎉</view>
          <text class="menu-text">活动管理</text>
          <text class="menu-arrow">></text>
        </view>
      </view>

      <view class="menu-group">
        <view class="menu-item" @click="goToFinance">
          <view class="menu-icon">💰</view>
          <text class="menu-text">收支明细</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToStatistics">
          <view class="menu-icon">📊</view>
          <text class="menu-text">经营统计</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToReviews">
          <view class="menu-icon">⭐</view>
          <text class="menu-text">评价管理</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToRecords">
          <view class="menu-icon">📝</view>
          <text class="menu-text">核销记录</text>
          <text class="menu-arrow">></text>
        </view>
      </view>

      <view class="menu-group">
        <view class="menu-item" @click="goToHelp">
          <view class="menu-icon">❓</view>
          <text class="menu-text">帮助中心</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToFeedback">
          <view class="menu-icon">💬</view>
          <text class="menu-text">意见反馈</text>
          <text class="menu-arrow">></text>
        </view>
        <view class="menu-item" @click="goToAbout">
          <view class="menu-icon">ℹ️</view>
          <text class="menu-text">关于我们</text>
          <text class="menu-arrow">></text>
        </view>
      </view>
    </view>

    <!-- 退出登录 -->
    <view class="logout-section">
      <view class="logout-btn" @click="logout">
        <text class="logout-text">退出登录</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      userInfo: {
        name: '张师傅',
        phone: '138****8888',
        avatar: '/static/logo.png',
        status: '营业中'
      },
      userStats: {
        totalOrders: 156,
        totalIncome: '12,580.00',
        rating: '4.8',
        completedTasks: 89
      }
    }
  },
  onLoad() {
    this.getStatusBarHeight();
    this.loadUserInfo();
  },
  methods: {
    getStatusBarHeight() {
      const systemInfo = uni.getSystemInfoSync();
      this.statusBarHeight = systemInfo.statusBarHeight || 0;
    },
    
    loadUserInfo() {
      // TODO: 调用后端API获取用户信息
      // this.$api.getUserInfo().then(res => {
      //   this.userInfo = res.data;
      // });
    },
    
    changeAvatar() {
      uni.chooseImage({
        count: 1,
        sizeType: ['compressed'],
        sourceType: ['album', 'camera'],
        success: (res) => {
          // TODO: 上传头像
          this.userInfo.avatar = res.tempFilePaths[0];
          uni.showToast({
            title: '头像更新成功',
            icon: 'success'
          });
        }
      });
    },
    
    editProfile() {
      uni.navigateTo({
        url: '/pages/profile/edit'
      });
    },
    
    goToSettings() {
      // TODO: 跳转到设置页面
      uni.showToast({
        title: '功能开发中',
        icon: 'none'
      });
    },
    
    goToOrders() {
      uni.navigateTo({
        url: '/pages/orders/orders'
      });
    },
    
    goToTasks() {
      uni.navigateTo({
        url: '/pages/tasks/tasks'
      });
    },
    
    goToCoupons() {
      uni.navigateTo({
        url: '/pages/coupons/coupons'
      });
    },
    
    goToActivities() {
      uni.navigateTo({
        url: '/pages/activities/activities'
      });
    },
    
    goToFinance() {
      uni.navigateTo({
        url: '/pages/finance/finance'
      });
    },
    
    goToStatistics() {
      uni.navigateTo({
        url: '/pages/statistics/statistics'
      });
    },
    
    goToReviews() {
      uni.navigateTo({
        url: '/pages/reviews/reviews'
      });
    },
    
    goToRecords() {
      uni.navigateTo({
        url: '/pages/records/records'
      });
    },
    
    goToHelp() {
      // TODO: 跳转到帮助中心
      uni.showToast({
        title: '功能开发中',
        icon: 'none'
      });
    },
    
    goToFeedback() {
      // TODO: 跳转到意见反馈
      uni.showToast({
        title: '功能开发中',
        icon: 'none'
      });
    },
    
    goToAbout() {
      // TODO: 跳转到关于我们
      uni.showToast({
        title: '功能开发中',
        icon: 'none'
      });
    },
    
    logout() {
      uni.showModal({
        title: '确认退出',
        content: '确定要退出登录吗？',
        success: (res) => {
          if (res.confirm) {
            // TODO: 清除用户数据
            uni.removeStorageSync('token');
            uni.removeStorageSync('userInfo');
            
            uni.showToast({
              title: '已退出登录',
              icon: 'success'
            });
            
            setTimeout(() => {
              uni.reLaunch({
                url: '/pages/login/login'
              });
            }, 1500);
          }
        }
      });
    }
  }
}
</script>

<style scoped>
.profile-page {
  min-height: 100vh;
  background-color: #F5F5F5;
}

.status-bar {
  background-color: #007AFF;
}

.header {
  background-color: #007AFF;
  padding: 20rpx 30rpx;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.title {
  color: white;
  font-size: 36rpx;
  font-weight: bold;
}

.header-actions {
  display: flex;
  gap: 20rpx;
}

.action-btn {
  background-color: rgba(255, 255, 255, 0.2);
  padding: 10rpx 20rpx;
  border-radius: 20rpx;
}

.action-text {
  color: white;
  font-size: 28rpx;
}

.user-info {
  background-color: white;
  padding: 40rpx 30rpx;
  display: flex;
  align-items: center;
  gap: 30rpx;
  margin-bottom: 20rpx;
}

.user-avatar {
  position: relative;
  width: 120rpx;
  height: 120rpx;
  border-radius: 50%;
  overflow: hidden;
}

.avatar {
  width: 100%;
  height: 100%;
}

.edit-avatar {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 40rpx;
  height: 40rpx;
  background-color: #007AFF;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.edit-icon {
  font-size: 20rpx;
  color: white;
}

.user-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10rpx;
}

.user-name {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.user-phone {
  font-size: 26rpx;
  color: #666;
}

.user-status {
  display: inline-block;
  background-color: #E8F5E8;
  color: #52C41A;
  padding: 5rpx 15rpx;
  border-radius: 15rpx;
  font-size: 22rpx;
}

.edit-btn {
  background-color: #F5F5F5;
  padding: 15rpx 30rpx;
  border-radius: 25rpx;
}

.edit-text {
  font-size: 26rpx;
  color: #666;
}

.stats-section {
  background-color: white;
  padding: 30rpx;
  display: flex;
  justify-content: space-around;
  margin-bottom: 20rpx;
}

.stats-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10rpx;
}

.stats-number {
  font-size: 32rpx;
  font-weight: bold;
  color: #333;
}

.stats-label {
  font-size: 24rpx;
  color: #666;
}

.menu-section {
  margin-bottom: 20rpx;
}

.menu-group {
  background-color: white;
  margin-bottom: 20rpx;
}

.menu-item {
  display: flex;
  align-items: center;
  padding: 30rpx;
  border-bottom: 1rpx solid #F5F5F5;
}

.menu-item:last-child {
  border-bottom: none;
}

.menu-icon {
  width: 60rpx;
  height: 60rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32rpx;
  margin-right: 20rpx;
}

.menu-text {
  flex: 1;
  font-size: 28rpx;
  color: #333;
}

.menu-arrow {
  font-size: 24rpx;
  color: #999;
}

.logout-section {
  padding: 30rpx;
}

.logout-btn {
  background-color: white;
  padding: 30rpx;
  border-radius: 20rpx;
  text-align: center;
}

.logout-text {
  font-size: 28rpx;
  color: #FF4D4F;
}
</style>

















